package object;

import java.io.*;

public class HEAD implements Serializable {
    private Branch branch;
    public HEAD(){
        this.branch = new Branch();
        writeObject();
    }

    public String getKey(){
        return this.branch.getCommit().key;
    }

    public void updateHEAD(Commit commit){
        this.branch.setCommit(commit);
    }
    public void setBranch(Branch branch) { this.branch = branch;}
    public void writeObject() {
        try {

            ObjectOutputStream out =
                    new ObjectOutputStream(new FileOutputStream(".jit" + File.separator + "HEAD"));
            out.writeObject(this);
            out.close();
        }
        catch(Exception ex){
            ex.printStackTrace();
        }

    }
    public static HEAD deserialize() throws Exception{
        try{
            ObjectInputStream in = new ObjectInputStream(new FileInputStream(".jit" + File.separator + "HEAD"));
            return (HEAD) in.readObject();
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
